<?php
// 输出成绩表，利用表格，每行一个学生成绩信息  平时成绩占0.4 期末成绩占0.6，需要显示总成绩。
$scores = [
    [
        'id' => '2022000999',
        'name' => '张三',
        'score_1' => 90,
        'score_2' => 80
    ],
    [
        'id' => '2022000788',
        'name' => '李四',
        'score_1' => 78,
        'score_2' => 80
    ]
];
// sprintf("%.1f", $score)
?>
<html>
<head>
    <title>成绩表</title>
    <style>
        table tr th {background-color: aliceblue}
    </style>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>平时成绩</th>
            <th>期末成绩</th>
            <th>总成绩</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($scores as $key => $val):?>
        <tr>
            <td><?php echo $val['id'];?></td>
            <td><?php echo $val['name']?></td>
            <td><?php echo $val['score_1'];?></td>
            <td><?php echo $val['score_2'];?></td>
            <td><?php echo $val['score_1'] * 0.4 + $val['score_2'] * 0.6;?></td>
        </tr>
        <?php endforeach;?>
    </tbody>
</table>
</body>
</html>
